home *** CD-ROM | disk | FTP | other *** search
-
- // Copyright (c) 1998, 1999 Macromedia. All rights reserved.
-
- fw.checkFwJsVersion(0);
-
- var gBatchACommandIsAlreadyRunning; // for this to work, you must not initialize this to a value here.
-
- if (typeof(gBatchACommandIsAlreadyRunning) != "undefined") {
-
- // if this var is not undefined, we are trying to run this very
- // command on itself -- naughty.
- gBatchACommandIsAlreadyRunning = undefined;
- alert("You may not run this command on itself.");
- throw Errors.EUserCanceled;
-
- } else {
-
- // OK, define this var so that we can test it for recursion.
- // it doesn't really matter what we set the value to; we just
- // have to ensure the value is not undefined.
- gBatchACommandIsAlreadyRunning = true;
- try {
-
- // initialize these up front, so that the "progress" dialog
- // is forced to appear...
- App.progressCountCurrent = 0;
- App.progressCountTotal = 0;
- App.batchStatusString = "";
-
- var theJsfToBatch = LocateJsfFileToBatch();
-
- if (theJsfToBatch != null) {
- theDocList = App.chooseScriptTargetDialog(App.getPref("MultiFileBatchTypes"));
- if (theDocList == null) {
- // The user must have canceled the "select files" dialog.
- } else if (theDocList.length == 0) {
- // The user did something like "current files" when no files are open.
- alert(Errors.ENoFilesSelected);
- } else {
- App.progressCountCurrent = 0;
- App.progressCountTotal = theDocList.length;
- for (var i = 0; i < theDocList.length; i++) {
- App.progressCountCurrent = i + 1;
- App.batchStatusString = "";
- ProcessOneDocPath(theDocList[i], theJsfToBatch);
- }
- }
- }
-
- } catch (e) {
-
- // this resets this variable to being "undefined".
- gBatchACommandIsAlreadyRunning = undefined;
-
- // propagate the exception on out.
- throw e;
-
- }
-
- // this resets this variable to being "undefined".
- gBatchACommandIsAlreadyRunning = undefined;
-
- }
-
- // ----------------------------------------------------------
- function LocateJsfFileToBatch()
- {
- var kOpenLocPrefName = "LastOpenLocation";
- var savePref = App.getPref(kOpenLocPrefName);
- App.setPref(kOpenLocPrefName, App.appJsCommandsDir);
- var theJsfToBatchArray = App.locateDocDialog(1, ["Fireworks JavaScript"]);
- App.setPref(kOpenLocPrefName, savePref);
- var theJsfToBatch = theJsfToBatchArray != null ? theJsfToBatchArray[0] : null;
- return theJsfToBatch;
- }
-
- // ----------------------------------------------------------
- function ProcessOneDocPath(docPathName, jsfPath)
- {
- var theDocWasOpen = false;
- var theDoc = App.findOpenDocument(docPathName);
-
- if (theDoc == null) {
- theDoc = App.openDocument(docPathName, false);
- theDocWasOpen = false;
- } else {
- theDocWasOpen = true;
- }
-
- ProcessOneDoc(theDoc, jsfPath);
-
- if (theDoc != null && theDocWasOpen == false) {
- // save and close, without prompting user
- theDoc.save();
- theDoc.close(false);
- }
- }
-
- // ----------------------------------------------------------
- function ProcessOneDoc(theDoc, jsfPath)
- {
- var sourceDocumentPath = theDoc.filePathForSave;
- if (sourceDocumentPath == null)
- sourceDocumentPath = theDoc.filePathForRevert;
-
- if (sourceDocumentPath == null)
- App.batchStatusString = "(untitled)";
- else
- App.batchStatusString = Files.getFilename(sourceDocumentPath.toString());
-
- fw.setActiveWindow(theDoc, true);
-
- theDoc.exitPaintMode();
- theDoc.selectAll();
-
- fw.runScript(jsfPath);
- }
-